#include "watchdog/EtcdAgent.h"

#include "common/http/HttpRequest.h"
#include "common/http/HttpResponse.h"

#include <iostream>
using namespace std;

EtcdAgent::EtcdAgent(/* args */) {}

EtcdAgent::EtcdAgent(const SocketAddress &addr)
    : HttpAgent(addr)
{}

EtcdAgent::~EtcdAgent() {}

int EtcdAgent::connectAfter(bool bConnect)
{
    if (bConnect) {
        HttpRequest *req = new HttpRequest("/version");
        req->setHeader(HttpRequest::kHost, getHost());
        std::string sendBuf = req->packageSendData();
        sendPackage(sendBuf);
        delete req;
        return SUCCESSFUL;
    } else {
        return FAILED;
    }
}

void EtcdAgent::readBack(InReq &req)
{
    // 只有body
    cout << req.ioBuf << endl;
}